﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChatClient
{
    class ClientModel
    {
        List<ClientRoom> allRooms = new List<ClientRoom>();
        List<String> BufferedMessages = new List<String>();
        string m_UserName;

        int m_activeRoom;

        public void sendMsg(string Msg)
        {
        }

        public void sendToSrv(string Msg, ClientRoom curRoom)
        {
        }


        public string activateRoom (ClientRoom curRoom)
        {
            for (int i = 0; i < allRooms.Count; i++)
            {
                if (String.Compare(allRooms[i].getName(), curRoom.getName()) == 0)
                {
                    string i = String.Copy(BufferedMessages[m_activeRoom]);
                    BufferedMessages[m_activeRoom] = "";
                    return i;
                }
            }

            return "";
        }

        public void messageReceived (string Msg, String roomID)
        {
            for (int i = 0; i < allRooms.Count; i++)
            {
                if (String.Compare(allRooms[i].getName(), roomID) == 0)
                {
                    BufferedMessages[i] += "\n" + Msg;
                }
   
            }
        }

        public string BufferedMsgs()
        {
            string i = String.Copy(BufferedMessages[m_activeRoom]);
            BufferedMessages[m_activeRoom] = "";
            return i;
        }

        public void joinRoom (string roomName) {

        }

        public int ConnectToSrv(string _UserName)
        {

            return getConnectionResult();
        }
        /// <summary>
        /// Getting connection result
        /// </summary>
        /// <returns>
        /// 0 if not connected,
        /// 1 if username already exists,
        /// 2 if connection was successful </returns>
        public int getConnectionResult()
        {
            return 0;
        }
    }
}
